#1
from django.db.models.expressions import result

print("Hello World")

#2
old_age = '23'
height = 1.70
name = "Tom"
is_student = False

#3
like_fruit = ['Apple', 'Orange', 'Mango', 'Pineapple', ]

#4
person = {
    "name": "jery",
    "age": 20
}

#5
yuanzu = (like_fruit,name)
print(yuanzu)

#6 controller
age = 101
if 18 <= age <= 100:
    print("This is > in 18")
elif age <= 13:
    print("This is not in 18")
elif 100 < age < 200:
    print('100 - 200')
else:
    print("This is not in 18")


for i in range(1,5):
    # print(1)
    print(i)


num = 1
while True:
    print("hello")
    num += 1
    if num > 5:
        break


count = 0
while count < 5:
    print(count)
    count += 1
    print(count)
    print("=====")

#7 FUNC
def hanshu():
    print("hello，2025".format())

hanshu()

# error
try:
    hanshu()
    print("hello".format())
except Exception as e:
    print(f"待处理报错为",e)


def getname(name):
    return f"hello,{name}"

message = getname("alice")

print(message)

# 8 oop
class Dog:
    def __init__(self,name):
        self.name = name

    def bark(self):
        print(f"{self.name} say Woof!",self.name)

mydog = Dog("wang")
mydog.bark()


# 异常处理
try:
    result = 10/0
except Exception as e:
    # print("Error:Can not divide by zero ")
    print(e)
finally:
    print("This is always execute!")


# write
# with open("test.txt","w") as f:
#     #\n换行写入
#     f.write("This is always execute!\n")
#     f.write("This is always execute!")

# read (文档为中文则出错)
with open("test.txt", "r") as f:
    content = f.read()
    print(content)


with open("test.txt", "r",encoding='utf-8') as f:
    content = f.read()
    print(content)

try:
    with open("test.txt", "r", encoding="utf-8") as f:
        content = f.read()
        print(content)
except UnicodeDecodeError:
    print("UTF-8 编码读取失败，尝试其他编码...")
except Exception as e:
    # print(e)
    print(f"广播发送失败: {e}")
